package Logic;

import irio.gamer.gamer;

import java.io.File;
import java.io.FilenameFilter;

import javax.swing.filechooser.FileNameExtensionFilter;

public class Spectra {

	public String[] spectra;
	public double[] spectraVal;
	
	public Spectra() {
		FilenameFilter filter = new FilenameFilter() {
			
			public boolean accept(File dir, String name) {
				if(name.lastIndexOf('.')>0)
	               {
	                  // get last index for '.' char
	                  int lastIndex = name.lastIndexOf('.');
	                  
	                  // get extension
	                  String str = name.substring(lastIndex);
	                  
	                  // match path name extension
	                  if(str.equals(".txt"))
	                  {
	                     return true;
	                  }
	                  if(str.equals(".lis"))
	                  {
	                     return true;
	                  }
	               }
	               return false;
			}
		};
		File directory = new File(gamer.gamerParams.spectraDir);
		spectra = directory.list(filter);
		spectraVal = new double[spectra.length];
		for (int i = 0; i < spectra.length; i++) {
			spectraVal[i] = i;
		}
	}
	
	public int find(String s) {
		for (int i=0;i<spectra.length;i++)
			if (s.equals(spectra[i]))
				return i;
		
		return 0; // default spectrum
	}
	
}
